import request from '@/utils/request';
import {generateNonce} from "@/utils";

export interface R<T> {
    data: T
}

export interface User {
    nickname: string;
    avatar: string;
    score: number;
    isSelf: boolean
}

/**
 * 设置用户信息
 */
export const setUserInfo = (user: Pick<User, 'nickname' | 'avatar'>) => {
    return request.post('/setUserInfo', user)
}

/**
 * 获取排行榜
 */
export const getRankingList = (): Promise<R<User[]>> => {
    return request.get(`/getRankingList?nonce=${generateNonce()}`)
}

/**
 * 更用户分数
 */
export const updateScore = (score: number) => {
    return request.post('/updateScore', {score})
}

/**
 *获取当前用户信息
 */
export const getUserInfo = (): Promise<R<User>> => {
    return request.get(`/getUserInfo?nonce=${generateNonce()}`)
}

